<?php

namespace JsonLowCode\Form\Fields;

use JsonLowCode\UI\Checkboxes;
use JsonLowCode\Form\Abstract\FieldAbstract;
use JsonLowCode\Form\Traits\HasDisabled;
use JsonLowCode\Form\Traits\HasSize;

/**
 * @property Checkboxes $element
 */
class CheckBoxField extends FieldAbstract
{

    use HasDisabled, HasSize;

    protected bool $group = false;

    protected mixed $options = [];

    protected function booting(): void
    {
        $this->element = new Checkboxes();
    }

    /**
     * @param array $options
     * @return $this
     */
    public function options(array $options = []): static
    {
        $this->options = $options;
        return $this;
    }


    protected function setOptions(): void
    {
        $options = [];
        foreach ($this->options as $key=>$option){
            if (!is_array($option)){
                $option = ['label'=>$option,'value'=> $key];
            }
            $options[] = $option;
        }
        $this->element->options($options);
    }

    protected function render(): void
    {
        $this->setOptions();
    }
}
